<?php
namespace app\interfaces\controller;

use app\interfaces\model\MemberPacket as MemberPacketModel;
use think\Request;
use think\Exception;

class MemberPacket
{

    /*
     * 用户端 - 我的红包列表
     * @param  string $user_id      会员ID
     * @param  string $status       使用状态
     * @param  string $end_time     已过期
     */
    public function collect_list()
    {

        // 获取参数
        $data = Request::instance()->param();

        if (empty($data['user_id'])) throw new Exception('not Empty');

        // 搜索条件
        $condition['member_id'] = ['eq', $data['user_id']];
        $condition['end_time'] = ['egt', time()];
        $condition['status'] = ['eq', '2'];

        if (!empty($data['status'])) $condition['status'] = ['eq', '1'];
        if (!empty($data['time'])) $condition['end_time'] = ['elt', time()];

        // 读取
        $model = new MemberPacketModel();

        $result = $model->where($condition)
            ->field('member_id,shop_id,create_time,status,coupon_id', true)
            ->order(['id' => 'desc'])
            ->paginate(6);


        return ['code' => 200, 'message' => '成功', 'data' => $result];
    }

}
